package com.lt.lumentracks.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lt.lumentracks.entity.po.Follow;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lt.lumentracks.entity.po.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 关注表 Mapper 接口
 * </p>
 *
 * @author swl
 * @since 2025-09-03
 */
public interface FollowMapper extends BaseMapper<Follow> {

    // 根据用户名字模糊查询我的关注
    // 先用 f.user_id = ? 筛选出一部分的user，然后再在这部分user中查找名字包含“xxx”的user （大数据量的情况下绝对不能先进行模糊查询，会有严重的性能问题）
    @Select("SELECT u.* " +
            "FROM user u " +
            "JOIN follow f ON u.id = f.follow_user_id " +
            "WHERE f.user_id = #{userId} " +
            "AND u.username LIKE concat('%',#{followName},'%')" +
            "ORDER BY f.create_time DESC")
    IPage<User> selectUserByFollowAndName(@Param("followName")String followName,
                                          @Param("userId")Integer userId,
                                          Page<User> page);
}
